package com.myk.game.lib.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;
import com.myk.game.lib.DrawElement;
import java.util.ArrayList;
import java.util.List;

/**
 * 棋盘视图
 */
public class ChessBoardView extends View {

    private final List<DrawElement> drawElementList = new ArrayList<>();
    private final Paint paint = new Paint();

    public ChessBoardView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        for (DrawElement drawElement : drawElementList) {
            drawElement.onDraw(canvas, paint);
        }
    }

    public void addDrawElement(DrawElement drawElement) {
        drawElementList.add(drawElement);
        invalidate();
    }

    @Override
    public boolean performClick() {
        return super.performClick();
    }
}
